<template>
  <el-container class="home-container">
    <!--    头部-->
    <el-header>
      <div>
        <img src="../assets/logo.png" alt="">
      </div>
      <span>图书管理系统</span>
      <el-button type="info" @click="logout">安全退出</el-button>
    </el-header>
    <!--    主体-->
    <el-container>
      <!--      侧边栏-->
      <el-aside width="200px">
        <el-menu
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :router="true"
            default-active="/user"
        >
          <!--          一级菜单-->
          <el-submenu :index="item.path" v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{ item.title }}</span>
            </template>
            <!--二级菜单-->
            <el-menu-item :index="it.path" v-for="it in item.subMenuList" :key="it.id">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{ it.title }}</span>
              </template>
            </el-menu-item>


          </el-submenu>

        </el-menu>

      </el-aside>
      <el-container>
        <!--        主题内容-->
        <el-main>
          <router-view>

          </router-view>

        </el-main>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      //菜单列表
      menuList: [],
    }
  },
  created() {
    // 查询菜单列表
    this.getMenuList();
    console.log(this.getMenuList())

  },
  methods: {
    // 退出
    logout() {
      window.sessionStorage.clear();// 退出清除sessionStorage
      this.$router.push("/login")
    },
    getMenuList() {
      axios.get('/menus', this.menuList).then(res => {
        if (res.data.flag != 200) {
          return this.$message.error("获取列表失败");
        } else {
          this.menuList = res.data.menus;
        }
        console.log(res.data)
      })
    },

  }
}
</script>

<style scoped>
.home-container {
  height: 100%;
}

.el-header {
  display: flex;
  justify-content: space-between;
  background-color: #373d41;
  padding-left: 20px;
  padding-right: 20px;
  color: #eaedf1;
  font-size: 20px;
  align-items: center;

}

.el-aside {
  background-color: #333744;

}
.el-menu{
  border-right: none;
}

.el-main {
  background-color: #eaedf1;
}

img {
  width: 50px;
  height: 50px;
}


</style>